package com.gzdh.tang.modu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.gzdh.tang.modu.entity.Addr;
import com.gzdh.tang.modu.entity.TangDevice;
import com.gzdh.tang.modu.mapper.TangAddrMapper;
import com.gzdh.tang.modu.service.TangAddrService;
import com.gzdh.tang.modu.service.TangDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Slf4j
@Service("tangAddrServiceImpl")
public class TangAddrServiceImpl extends ServiceImpl<TangAddrMapper, Addr> implements TangAddrService {

    @Autowired
    TangDeviceService tangDeviceService;

    @Autowired
    TangAddrMapper tangAddrMapper;

    @Override
    public List<Addr> getAddrByOpera(String operaId) {
        TangDevice tangDevice = tangDeviceService.getOne(new QueryWrapper<TangDevice>().lambda().eq(TangDevice::getPosnum, operaId));
        if (tangDevice == null) {
            return new ArrayList<>();
        }
        return tangAddrMapper.getAddrTree(tangDevice.getAddr());

    }
}
